import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:video_player/video_player.dart';
import '../../../hj_model/video_model.dart';
import '../../darkweb/widget/shrink_wrap.dart';
import '../../home_business/tag/carrtoon_tag_page.dart';


class VideoDetailCartoonInfoWidget extends StatelessWidget {
  final VideoModel? model;
  final VideoPlayerController? controller;

  const VideoDetailCartoonInfoWidget({
    super.key,
    this.model,
    this.controller,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        _buildRichText(),
        _buildTags(),
      ],
    );
  }

  Widget _buildRichText() {
    if (model?.title?.trim().isNotEmpty == true)
      return Container(
        padding: EdgeInsets.only(bottom: 0),
        child: Text(
          model?.title?.trim() ?? "",
          style: TextStyle(
            color: Colors.white,
            height: 1.5,
            fontSize: 16,
            fontWeight: FontWeight.w500,
          ),
        ),
      );
    return SizedBox();
  }

  Widget _buildTags() {
    if (model?.tags?.isNotEmpty == true) {
      return Container(
        padding: EdgeInsets.only(top: 12),
        child: ShrinkWrap(
          spacing: 0,
          runSpacing: 6,
          maxLines: 1,
          children: model!.tags!.map((e) => _buildTagItem(e)).toList(),
        ),
      );
    }
    return const SizedBox();
  }

  Widget _buildTagItem(TagsBean tag) {
    return InkWell(
      onTap: () {
        controller?.pause();
        Get.to(CartoonTagPage(title: tag.name ?? "", sId: tag.id), preventDuplicates: true);
      },
      child: Container(
        padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
        margin: EdgeInsets.only(right: 6),
        decoration: BoxDecoration(
          color: Color(0x1AFD2D55),
          borderRadius: BorderRadius.circular(3),
        ),
        child: Text(
          "#${tag.name}",
          style: TextStyle(
            color: Color(0xffFD2D55),
            fontSize: 11,
          ),
        ),
      ),
    );
  }
}
